package com.baturu.vin.gm.dal.dao;

import com.baturu.vin.gm.dto.CarSystemBtrIdDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface CarSystemBtrIdDAO {

    @Select("SELECT id,brand,subBrand,carSystem,chasis,mj,carType,btrId,carSystemId " +
            "FROM gm_carsystem " +
            "WHERE chasis = #{chasis} and mj = #{mj} limit 1")
    CarSystemBtrIdDTO findCarSystemBtrId(@Param("chasis") String chasis, @Param("mj") String mj);

    @Select({"SELECT max(btrId)",
            "FROM gm_carsystem"})
    String findMaxBtrId();

    @Select("SELECT DISTINCT brand,subBrand,carSystem,chasis,carType,carSystemId " +
            "FROM gm_carsystem " +
            "WHERE chasis = #{chasis}")
    List<CarSystemBtrIdDTO> findCarSystemBtrIdByChasis(@Param("chasis") String chasis);

    @Insert({"INSERT INTO gm_carsystem (",
            "brand,subBrand,carSystem,chasis,mj,carType,btrId,carSystemId",
            ") values (",
            "#{dto.brand},#{dto.subBrand},#{dto.carSystem},#{dto.chasis},#{dto.mj},#{dto.carType},#{dto.btrId},#{dto.carSystemId})"})
    int insertNewCarType(@Param("dto") CarSystemBtrIdDTO dto);
}
